package com.masterclient.app.businessmodule.minemodule.point.contract;

import com.eoner.baselib.enums.FCPageViewState;
import com.eoner.baselib.presenter.ThrowableConsumer;
import com.masterclient.app.businessmodule.minemodule.api.MineHttpService;
import com.eoner.baselib.container.CommonBaseResponse;
import com.masterclient.app.businessmodule.minemodule.point.model.PointMainBean;

import io.reactivex.functions.Consumer;

public class PointMainPresenter extends PointMainContract.Presenter{


    @Override
    public void getPointMain() {
        mView.baseShowPageLoading(false);
        mRxManager.add(toSubscribe(MineHttpService.getInstance().pointMain(), new Consumer<CommonBaseResponse<PointMainBean>>() {
            @Override
            public void accept(CommonBaseResponse<PointMainBean> pointMainBean) throws Exception {
                mView.baseHiddenPageLoading();
                mView.baseRefreshPageState(FCPageViewState.PAGE_STATE_NORMAL);
                if (pointMainBean.getCode() == 0){
                    mView.showData(pointMainBean.getData());
                }else {
                    String msg = pointMainBean.getMsg() != null && pointMainBean.getMsg().length() > 0 ? pointMainBean.getMsg() : WEB_FAILED_STR;
                    mView.baseRefreshPageState(FCPageViewState.PAGE_STATE_NET_ERROR,msg);
                    mView.loadFail(msg);
                }
            }
        },new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                mView.baseHiddenPageLoading();
                mView.baseRefreshPageState(FCPageViewState.PAGE_STATE_NET_ERROR,WEB_FAILED_STR);
                mView.loadFail("网络异常，请重试");
            }
        }));
    }
}
